package com.thghh.ch2;

/**
 * @author Zhikang.Peng
 * @version 1.0
 * @email thghh@qq.com
 * @date 2020/6/2 10:49
 */
public class JumpConsistentHash {

    public long jumpConsistentHash(long key, int numBuckts) {
        long b = -1 ,j = 0;
        while(j < numBuckts) {
            b = j;
            key = key * 2862933555777941757L + 1;
            j = (b + 1) * (1L << 31) / ((key >>> 33)  + 1);
        }
        return b;
    }

}
